Handle ObjectDisposedException in SignalR OnDisconnectedAsync during shutdown#65457
Draft
adityamandaleeka wants to merge 2 commits intodotnet:mainfrom
Draft
Handle ObjectDisposedException in SignalR OnDisconnectedAsync during shutdown#65457adityamandaleeka wants to merge 2 commits intodotnet:mainfrom
adityamandaleeka wants to merge 2 commits intodotnet:mainfrom
Conversation
…xception Long polling DELETE fire-and-forgets server-side connection disposal, so OnDisconnectedAsync can race with host shutdown and hit a disposed IServiceProvider. This produces up to two error logs (ErrorDispatchingHubEvent and FailedDispose) that VerifyNoErrorsScope catches nondeterministically.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a flaky test (TestServerTests.LongPollingWorks) that intermittently fails in CI due to a race condition during test teardown. The test uses long polling transport, which fire-and-forgets the server-side connection disposal. When the test host shuts down, the background OnDisconnectedAsync can race with the disposal of the IServiceProvider, resulting in up to two ObjectDisposedException error logs that cause the test to fail nondeterministically. This is not a product bug—it's an expected behavior during shutdown.
Changes:
- Added
expectedErrorsFiltertoStartVerifiableLog()to tolerateObjectDisposedExceptionduring test teardown - Added
Systemnamespace import forObjectDisposedException - Added explanatory comment documenting the race condition
Member
Author
|
Marking draft while an updated fix is prepared... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
TestServerTests.LongPollingWorksfails intermittently in CI with:Root Cause
ProcessDeleteAsyncinHttpConnectionDispatcherfire-and-forgets server-side connection disposal. When the host shuts down,OnDisconnectedAsynccan race withIServiceProviderdisposal, causingObjectDisposedExceptionwhen creating a DI scope or resolving services.Fix
Catch
ObjectDisposedExceptionat both framework DI boundaries inDefaultHubDispatcher.OnDisconnectedAsync:CreateAsyncScope()fails if the root provider is already disposedGetRequiredService/hubActivator.Create()can fail if the root provider is disposed after scope creationIn both cases, the host is shutting down and the DI container cannot service requests, so we log at Debug level and no-op gracefully. User hub code exceptions (
Hub.OnDisconnectedAsync, middleware) are not caught — only framework DI plumbing is protected.Since the error is now handled at the source, the
LongPollingWorkstest does not need anexpectedErrorsFilter.